home *** CD-ROM | disk | FTP | other *** search
- /* Scheme In One Define.
-
- The garbage collector, the name and other parts of this program are
-
- * COPYRIGHT (c) 1989 BY *
- * PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS. *
-
- Conversion to full scheme standard, characters, vectors, ports, complex &
- rational numbers, and other major enhancments by
-
- * Scaglione Ermanno, v. Pirinoli 16 IMPERIA P.M. 18100 ITALY *
-
- Permission to use, copy, modify, distribute and sell this software and its
- documentation for any purpose and without fee is hereby granted, provided
- that the above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear in supporting
- documentation, and that the name of Paradigm Associates Inc not be used in
- advertising or publicity pertaining to distribution of the software without
- specific, written prior permission.
-
- PARADIGM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- PARADIGM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
- IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <setjmp.h>
- #include <signal.h>
- #include <math.h>
- #include <limits.h>
-
- #include "siod.h"
-
-
- LISP negative(LISP x)
- {if NNUMBERP(x) err("negative?",x,ERR_GEN_ARG | ERR_NNUM);
- return EQ(truth,lessp(x,flocons(0.))) ? truth : NIL;}
-
- LISP positive(LISP x)
- {if NNUMBERP(x) err("positive?",x,ERR_GEN_ARG | ERR_NNUM);
- return EQ(truth,greaterp(x,flocons(0.))) ? truth : NIL;}
-
- LISP zerop(LISP x)
- {if NNUMBERP(x) err("zero?",x,ERR_GEN_ARG | ERR_NNUM);
- return EQ(truth,uguale(x,flocons(0.))) ? truth : NIL;}
-
- LISP odd(LISP x)
- {double tmp;
- x = tofloat(x);
- if (NFLONUMP(x)||(modf(FLONM(x),&tmp)!=0.))
- err("odd?",x,ERR_GEN_ARG | ERR_NINT);
- if(fmod(FLONM(x),2.)==0.)
- return(NIL);
- return(truth);}
-
- LISP even(LISP x)
- {double tmp;
- x = tofloat(x);
- if (NFLONUMP(x)||(modf(FLONM(x),&tmp)!=0.))
- err("even?",x,ERR_GEN_ARG | ERR_NINT);
- if(fmod(FLONM(x),2.)==0.)
- return(truth);
- return(NIL);}
-
-
- LISP lessp(LISP x,LISP y)
- {
- if NNUMBERP(x) err("<",x,ERR_FIRST | ERR_NNUM);
- if NNUMBERP(y) err("<",y,ERR_SECOND | ERR_NNUM);
- if(NCOMPNUMP(x) && NCOMPNUMP(y))
- {y=tofloat(y);
- x=tofloat(x);
- if(FLONM(x)<FLONM(y)) return(truth);}
- else
- {y=tocomplex(y);
- x=tocomplex(x);
- if(COMPRE(x)<COMPRE(y)) return(truth);
- else if((COMPRE(x) == COMPRE(y)) && (COMPIM(x)<COMPIM(y)))
- return(truth);}
- return(NIL);}
-
- LISP greaterp(LISP x,LISP y)
- {
- if NNUMBERP(x) err(">",x,ERR_FIRST | ERR_NNUM);
- if NNUMBERP(y) err(">",y,ERR_SECOND | ERR_NNUM);
- if(NCOMPNUMP(x) && NCOMPNUMP(y))
- {y=tofloat(y);
- x=tofloat(x);
- if(FLONM(x)>FLONM(y)) return(truth);}
- else
- {y=tocomplex(y);
- x=tocomplex(x);
- if(COMPRE(x)>COMPRE(y)) return(truth);
- else if((COMPRE(x) == COMPRE(y)) && (COMPIM(x)>COMPIM(y)))
- return(truth);}
- return(NIL);}
-
- LISP greatereqp(LISP x,LISP y)
- {
- if NNUMBERP(x) err(">=",x,ERR_FIRST | ERR_NNUM);
- if NNUMBERP(y) err(">=",y,ERR_SECOND | ERR_NNUM);
- if(NCOMPNUMP(x) && NCOMPNUMP(y))
- {y=tofloat(y);
- x=tofloat(x);
- if(FLONM(x)>=FLONM(y)) return(truth);}
- else
- {y=tocomplex(y);
- x=tocomplex(x);
- if(COMPRE(x)>=COMPRE(y)) return(truth);
- else if((COMPRE(x) == COMPRE(y)) && (COMPIM(x)>=COMPIM(y)))
- return(truth);}
- return(NIL);}
-
- LISP lesseqp(LISP x,LISP y)
- {
- if NNUMBERP(x) err("<=",x,ERR_FIRST | ERR_NNUM);
- if NNUMBERP(y) err("<=",y,ERR_SECOND | ERR_NNUM);
- if(NCOMPNUMP(x) && NCOMPNUMP(y))
- {y=tofloat(y);
- x=tofloat(x);
- if(FLONM(x)<=FLONM(y)) return(truth);}
- else
- {y=tocomplex(y);
- x=tocomplex(x);
- if(COMPRE(x)<=COMPRE(y)) return(truth);
- else if((COMPRE(x) == COMPRE(y)) && (COMPIM(x)<=COMPIM(y)))
- return(truth);}
- return(NIL);}
-
- LISP uguale(LISP x,LISP y)
- {
- if NNUMBERP(x) err("=",x,ERR_FIRST | ERR_NNUM);
- if NNUMBERP(y) err("=",y,ERR_SECOND | ERR_NNUM);
- if(NCOMPNUMP(x) && NCOMPNUMP(y))
- {y=tofloat(y);
- x=tofloat(x);
- if(FLONM(x)==FLONM(y)) return(truth);}
- else
- {y=tocomplex(y);
- x=tocomplex(x);
- if((COMPRE(x) == COMPRE(y)) && (COMPIM(x)==COMPIM(y)))
- return(truth);}
- return(NIL);}
-
- LISP diverso(LISP x,LISP y)
- {
- if NNUMBERP(x) err("<>",x,ERR_FIRST | ERR_NNUM);
- if NNUMBERP(y) err("<>",y,ERR_SECOND | ERR_NNUM);
- if(NCOMPNUMP(x) && NCOMPNUMP(y))
- {y=tofloat(y);
- x=tofloat(x);
- if(FLONM(x)!=FLONM(y)) return(truth);}
- else
- {y=tocomplex(y);
- x=tocomplex(x);
- if((COMPRE(x) != COMPRE(y)) || (COMPIM(x)!=COMPIM(y)))
- return(truth);}
- return(NIL);}
-
- LISP eq(LISP x,LISP y)
- {if(EQ(x,y)) return(truth);
- return(NIL);}
-
- LISP eql(LISP x,LISP y)
- {if(EQ(x,y))
- return(truth);
- if(NUMBERP(x) && NUMBERP(y))
- return(uguale(x,y));
- if(STRINGP(x) && STRINGP(y))
- if(strcmp(SNAME(x),SNAME(y))==0)
- return(truth);
- if(CHARP(x) && CHARP(y))
- if(CHARV(x)==CHARV(y))
- return(truth);
- return(NIL);}
-
- LISP equal(LISP x,LISP y)
- {long size1,size2,i;
- if(VECTORP(x) && VECTORP(y))
- {size1 = VECSIZE(x);
- size2 = VECSIZE(y);
- if(size1!=size2)
- return(NIL);
- for(i=0;i<size1;i++)
- if(equal(VECTOR(x)[i],VECTOR(y)[i])==NIL)
- return(NIL);
- return(truth);}
- if(CONSP(x) && CONSP(y))
- if((equal(CAR(x),CAR(y))==truth)&&(equal(CDR(x),CDR(y))==truth))
- return(truth);
- return(eql(x,y));}
-
- LISP integerp(LISP x)
- {double tmp;
- if (INTNUMP(x)|| (FLONUMP(x)&&(modf(FLONM(x),&tmp)==0.)))
- return(truth); else return(NIL);}
-
- LISP rationalp(LISP x)
- {if RATNUMP(x) return(truth); else return(NIL);}
-
- LISP floatp(LISP x)
- {if FLONUMP(x) return(truth); else return(NIL);}
-
- LISP complexp(LISP x)
- {if COMPNUMP(x) return(truth); else return(NIL);}
-
- int nump(LISP x)
- {switch(TYPE(x))
- {case tc_intnum:
- case tc_ratnum:
- case tc_flonum:
- case tc_compnum:
- return(1);
- default:
- return(0);}}
-
- LISP numberp(LISP x)
- {if(NUMBERP(x))
- return(truth);
- else
- return(NIL);}
-
- LISP realp(LISP x)
- {switch(TYPE(x))
- {case tc_intnum:
- case tc_ratnum:
- case tc_flonum:
- return(truth);
- default:
- return(NIL);}}
-